package edu.sctu.zhuyingzhi.month201505.day20150520.treadTest;

/**
 * Created by user13 on 2015/5/20.
 */
public class Store {
    private int count;
    private int size = 40;
    private int i = 0;

    public Store(){
        super();
    }

    synchronized void produce(String name){
        while(size == count){
            try {
                wait();

            }catch (Exception e){

                System.out.println("生产中断");
            }

        }
//        if (count > 48)
//            System.exit(1);
        System.out.println("test");
        count++;

        System.out.println(name + "生产了"+ count+"商品");
        notify();

    }

    synchronized void consume(String name){
        while(count == 0){
            try {
                wait();
            }catch (Exception e){
                System.out.println("消费中断");
            }
        }
            i++;
            if (i>50)
                System.exit(1);


            System.out.println("库存为："+count);
            System.out.println(name+ "消费了"+ i+"商品");
            count--;
            notify();

    }

}
